package com.lyfam.game.behaviosr.steering;

import com.lyfam.game.entity.MovingEntity;
import com.lyfam.game.geometry.Vector2D;

public class SeekingBehavior implements ISteeringBehavior
{
	public int getPriority()
	{
		return 3;
	}

	public int compareTo(ISteeringBehavior o)
	{
		if (getPriority() == o.getPriority())
		{
			return 0;
		}
		else
		{
			if (getPriority() >o.getPriority())
			{
				return 1;
			}
			else
			{
				return -1;
			}
		}
	}
	
	private MovingEntity vehicle;
	private Vector2D target;
	
	public SeekingBehavior(MovingEntity mov, Vector2D target)
	{
		this.vehicle = mov;
		this.target = target;
	}
	
	private Vector2D calculateSteeringForce()
	{
		Vector2D force = Vector2D.clone(target);
		force.sub(vehicle.getPosition());
		force.normalize();
		force.mult(vehicle.getMaxSpeed());
		force.sub(vehicle.getVelocity());
		return force;
	}
	
	public Vector2D getSteeringForce()
	{
		return calculateSteeringForce();
	}
	
}
